/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2009, Around(J2)ME				                                 **
 **   All rights reserved.                                                   **
 **                                                                          **
 **   This program and the accompanying materials are made available under   **
 **   the terms of the New BSD License which accompanies this    			 **
 **   distribution.											                 **
 **   A copy is found in the textfile LICENSE.txt							 **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Main developers:                                                       **
 **     Juri Strumpflohner		http://blog.js-development.com	             **
 **		Matthias Braunhofer		http://matthias.jimdo.com                    **
 **                                                                          **
 **  **********************************************************************  */

package com.aroundj2me.executableTasks;

import com.aroundj2me.model.ExecutableTask;
import com.aroundj2me.utility.HttpCommunicator;

/**
 * Does a call to the Around(J2)ME server for fetching all places for a certain
 * continent
 */
public class ContinentRetriever extends ExecutableTask {
	private String url = null;
	private String continent = null;

	public ContinentRetriever(String url) {
		this.url = url;
	}
	
	public ContinentRetriever(String url, String continent){
		this(url);
		this.continent = continent;
	}

	private String createURL() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(url);
		buffer.append("?continent=");
		buffer.append(HttpCommunicator.urlEncode(continent));

		return buffer.toString();
	}

	public void run() {
		super.run();
		
		String url = createURL();

		try {
			byte[] returnedData = HttpCommunicator.executeHTTPGet(url);
			
			notifyTaskFinished(new String(returnedData));
		} catch (Exception e) {
			notifyError(e.getMessage());
		}
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getContinent() {
		return continent;
	}

	public void setContinent(String continent) {
		this.continent = continent;
	}

}
